
#include <stdio.h>
#include <stdlib.h>

// 节点结构体
struct ListNode {
    int val;
    struct ListNode *next;
};

// 创建新节点
struct ListNode* createNode(int val) {
    struct ListNode *node = (struct ListNode*)malloc(sizeof(struct ListNode));
    node->val = val;
    node->next = NULL;
    return node;
}

// 删除重复元素
struct ListNode* deleteDuplicates(struct ListNode* head) {
    if (head == NULL) {
        return NULL;
    }
    
    struct ListNode *current = head;
    while (current->next != NULL) {
        if (current->val == current->next->val) {
            struct ListNode *temp = current->next;
            current->next = current->next->next;
            free(temp);
        } else {
            current = current->next;
        }
    }
    
    return head;
}

// 打印链表
void printList(struct ListNode *head) {
    struct ListNode *current = head;
    while (current != NULL) {
        printf("%d ", current->val);
        current = current->next;
    }
    printf("\n");
}

int main() {
    // 创建示例链表 1->1->2->3->3
    struct ListNode *head = createNode(1);
    head->next = createNode(1);
    head->next->next = createNode(2);
    head->next->next->next = createNode(3);
    head->next->next->next->next = createNode(3);
    
    printf("原始链表: ");
    printList(head);
    
    // 删除重复元素
    struct ListNode *newHead = deleteDuplicates(head);
    
    printf("删除重复元素后的链表: ");
    printList(newHead);
    
    return 0;
}

